package com.sgb.kjwl.view.ui.activity.enterprise;

import android.graphics.Color;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityServiceQuoteListBinding;
import com.sgb.kjwl.di.enterprise.DaggerEnterpriseComponent;
import com.sgb.kjwl.di.enterprise.EnterpriseModule;
import com.sgb.kjwl.model.entity.enterprise.TeamIntelligenceEntity;
import com.sgb.kjwl.model.entity.enterprise.UserCenterTeamIntelligenceEntity;
import com.sgb.kjwl.view.ui.adapter.enterprise.TeamIntelligenceAdapter;
import com.sgb.kjwl.view.ui.adapter.enterprise.UserCenterTeamIntelligenceAdapter;
import com.sgb.kjwl.viewmodel.enterprise.TeamIntelligenceListModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.List;

import javax.inject.Inject;

public class TeamIntelligenceListActivity extends AppActivity {

	@Inject
	TeamIntelligenceListModel model;
	private ActivityServiceQuoteListBinding binding;

	String teamNo = "";
	boolean isUserCenter = false;
	TeamIntelligenceAdapter teamIntelligenceAdapter;
	UserCenterTeamIntelligenceAdapter userAdapter;

	@Override
	protected void setupActivityComponent(AppComponent appComponent) {
		DaggerEnterpriseComponent.builder().appComponent(appComponent)
				.enterpriseModule(new EnterpriseModule(this))
				.build()
				.inject(this);
	}

	//设置状态栏为暗
	@Override
	protected boolean statusBarDark() {
		if (!isUserCenter)
			isUserCenter = getIntent().getBooleanExtra("isUserCenter", false);
		return isUserCenter;
	}

	@Override
	protected void initView() {
		super.initView();
		binding = DataBindingUtil.setContentView(this, R.layout.activity_service_quote_list);

//		if (isUserCenter) {
//			binding.include.liuhaiStatusView.setBackgroundResource(R.color.white);
//			binding.include.rlTitle.setBackgroundResource(R.color.white);
//			binding.include.ivBack.setImageResource(R.mipmap.btn_back3);
//			binding.include.titleView.setTextColor(Color.BLACK);
//		} else {
//			binding.include.liuhaiStatusView.setBackgroundResource(R.mipmap.navigation_bar);
//			binding.include.rlTitle.setBackgroundResource(R.mipmap.navigation_bar);
//			binding.include.ivBack.setImageResource(R.mipmap.back);
//			binding.include.titleView.setTextColor(Color.WHITE);
//		}
		binding.actionBar.setTitle("团队资质");
		teamNo = getIntent().getStringExtra("teamNo");


		if (teamIntelligenceAdapter == null)
			teamIntelligenceAdapter = new TeamIntelligenceAdapter(this, null);

		if (userAdapter == null)
			userAdapter = new UserCenterTeamIntelligenceAdapter(this, null);

		LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
		binding.displayView.setLayoutManager(layoutManager);
		binding.displayView.setAdapter(teamIntelligenceAdapter);
		binding.displayView.setLoadingMoreEnabled(true);
		binding.displayView.setLoadingListener(new XRecyclerView.LoadingListener() {
			@Override
			public void onRefresh() {
				if (isUserCenter) {
					model.getTeamIntelligenceListUserCenter(false);
				} else {
					model.getTeamIntelligenceList(false, teamNo);
				}

			}

			@Override
			public void onLoadMore() {
				if (isUserCenter) {
					model.getTeamIntelligenceListUserCenter(true);
				} else {
					model.getTeamIntelligenceList(true, teamNo);
				}

			}
		});


		if (isUserCenter) {
			model.getTeamIntelligenceListUserCenter(false);
		} else {
			model.getTeamIntelligenceList(false, teamNo);
		}

	}


	public void showList(List<TeamIntelligenceEntity> list, boolean isLoadMore) {
		binding.displayView.refreshComplete();
		binding.displayView.setAdapter(teamIntelligenceAdapter);
		if (isLoadMore) {
			if (null != list && list.size() > 0) {
				binding.displayView.loadMoreComplete();
				teamIntelligenceAdapter.addDatas(list);
			} else {
				binding.displayView.setNoMore(true);
			}
			binding.displayView.setVisibility(View.VISIBLE);
		} else {
			if (list.size() == 0) {
				binding.emptyView.setVisibility(View.VISIBLE);
			} else {
				binding.emptyView.setVisibility(View.GONE);
			}
			binding.displayView.refreshComplete();
			binding.displayView.setLoadingMoreEnabled(true);
			teamIntelligenceAdapter.setDatas(list);
		}
	}


	public void showUserList(List<UserCenterTeamIntelligenceEntity> list, boolean isLoadMore) {
		binding.displayView.refreshComplete();
		binding.displayView.setAdapter(userAdapter);
		if (isLoadMore) {
			if (null != list && list.size() > 0) {
				binding.displayView.loadMoreComplete();
				userAdapter.addDatas(list);
			} else {
				binding.displayView.setNoMore(true);
			}
			binding.displayView.setVisibility(View.VISIBLE);
		} else {
			if (list.size() == 0) {
				binding.emptyView.setVisibility(View.VISIBLE);
			} else {
				binding.emptyView.setVisibility(View.GONE);
			}
			binding.displayView.refreshComplete();
			binding.displayView.setLoadingMoreEnabled(true);
			userAdapter.setDatas(list);
		}
	}
}